package cn.cdeden.knowledge.service.impl;

import cn.cdeden.common.core.utils.MapstructUtils;
import cn.cdeden.common.core.utils.StringUtils;
import cn.cdeden.common.core.utils.page.TableDataInfo;
import cn.cdeden.common.mybatis.validator.QueryHelpMybatisPlus;
import cn.cdeden.common.satoken.utils.LoginHelper;
import cn.cdeden.knowledge.domain.Team;
import cn.cdeden.knowledge.domain.TeamFilesTree;
import cn.cdeden.knowledge.domain.TeamRole;
import cn.cdeden.knowledge.domain.TeamType;
import cn.cdeden.knowledge.domain.dto.*;
import cn.cdeden.knowledge.domain.vo.TeamInformationVo;
import cn.cdeden.knowledge.enums.PermTypeEnum;
import cn.cdeden.knowledge.enums.TeamTypeEnum;
import cn.cdeden.knowledge.mapper.FilesCollectionMapper;
import cn.cdeden.knowledge.mapper.TeamMapper;
import cn.cdeden.knowledge.mapper.TeamTypeMapper;
import cn.cdeden.knowledge.service.*;
import cn.cdeden.knowledge.utils.*;
import cn.cdeden.system.api.RemoteDeptService;
import cn.cdeden.system.api.RemotePostService;
import cn.cdeden.system.api.RemoteRoleService;
import cn.cdeden.system.api.RemoteUserService;
import cn.cdeden.system.api.model.LoginUser;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.antlr.v4.runtime.misc.MultiMap;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.util.*;

/**
 * @author Chen
 * @date 2022-09-05
 */
@Service
@Slf4j
@AllArgsConstructor
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
public class TeamServiceImpl extends ServiceImpl<TeamMapper, Team> implements TeamService, CoreTeamService {

//    private final RedisUtils redisUtils;
    private final TeamMapper teamMapper;

    private final TeamTypeMapper teamTypeMapper;

    private final TeamMemberService teamMemberService;

    private final TeamFilesTreeService teamFilesTreeService;

    private final TeamRelevanceTypeService teamRelevanceTypeService;

    public final CoreConfigUtils coreConfigUtils;

//    private final FileStorageUtils fileStorageUtils;
//    private final RemoteFileService remoteFileService;

    private final TeamRoleService teamRoleService;

    private final TeamRelevanceRoleService teamRelevanceRoleService;
    @DubboReference
    private final RemoteUserService sysUserService;

    private final FilesCollectionMapper filesCollectionMapper;
    @DubboReference
    private final RemoteDeptService sysDeptService;
    @DubboReference
    private final RemoteRoleService sysRoleService;
    @DubboReference
    private final RemotePostService remotePostService;

    @Override
    public TableDataInfo<TeamDto> queryByPerm(TeamQueryParam queryParam, Pageable pageable) {
        IPage<Team> queryPage = PageUtil.toMybatisPage(pageable);
        QueryWrapper<Team> predicate = QueryHelpMybatisPlus.getPredicate(queryParam);
        predicate.isNull("delete_id");

        //查询权限
        LoginUser user = LoginHelper.getLoginUser();
        List<TeamMemberDto> teamMemberDtos = teamMemberService.getTeamByMemberDto(user.getUserId());
        if (teamMemberDtos.size() > 0) {
            predicate.and(wrap -> {
                for (int i = 0; i < teamMemberDtos.size(); i++) {
                    if (i == 0) {
                        wrap.eq("id", teamMemberDtos.get(i).getTeamId());
                    } else {
                        wrap.or().eq("id", teamMemberDtos.get(i).getTeamId());
                    }
                }
            });
        } else {
            return null;
        }

        //查询收藏
        if (queryParam.getType().equals("1")) {
            predicate.and(wrap -> {
                wrap.apply("id = ANY(SELECT tree_node_id FROM files_collection WHERE file_type = 3 AND user_id = " + user.getUserId() + ")");
            });
        }
        String typeId = queryParam.getTypeId();
        //查询分类
        if (typeId != null && queryParam.getType().equals("2")) {
            List<String> byTypeId = teamRelevanceTypeService.getByTypeId(typeId);
            if (byTypeId.size() == 0) {
                return new TableDataInfo<>();
            }
            predicate.in("id", byTypeId);
        }
        predicate.orderByDesc("create_time");
        IPage<Team> page = teamMapper.selectPage(queryPage, predicate);
//        for (int i = 0; i < page.getRecords().size(); i++) {
//            User createUser = sysUserService.getById(Long.valueOf(page.getRecords().get(i).getOwner()));
//            if (createUser != null)
//                page.getRecords().get(i).setCreateBy(createUser.getNickName());
//
//            User updateUser = sysUserService.getById(Long.valueOf(page.getRecords().get(i).getUpdateId()));
//            if (updateUser != null)
//                page.getRecords().get(i).setUpdateBy(updateUser.getNickName());
//        }
        TableDataInfo<Team> build = TableDataInfo.build(page);
        TableDataInfo<TeamDto> teamDtoPageInfo = MapstructUtils.convertTableDataInfo(build, TeamDto.class);
        //是否收藏
//        PageInfo<TeamDto> teamDtoPageInfo = ConvertUtil.convertPage(page, TeamDto.class);
        List<TeamDto> teamDtos = teamDtoPageInfo.getRows();
        for (TeamDto teamDto : teamDtos) {
            String createId = teamDto.getCreateId();
            if (createId != null)
                teamDto.setCreateBy(createId);
            String updateId = teamDto.getUpdateId();
            if (updateId != null)
                teamDto.setUpdateBy(updateId);
            teamDto.setOwnerName(teamDto.getOwner());
            List<TeamType> byTeamId = teamTypeMapper.getByTeamId(teamDto.getId(), user.getUserId());
            teamDto.setTypes(byTeamId);
        }
        SetCollectionDataUtil setCollectionDataUtil = new SetCollectionDataUtil(filesCollectionMapper);
        teamDtoPageInfo.setRows(setCollectionDataUtil.setCollectionTeamData(teamDtos));
        return teamDtoPageInfo;
    }

    @Override
    public List<TeamDto> queryAll(TeamQueryParam query) {
        return MapstructUtils.convert(teamMapper.selectList(QueryHelpMybatisPlus.getPredicate(query)), TeamDto.class);
    }

    @Override
    public TableDataInfo<TeamDto> queryAll(TeamQueryParam query, Pageable pageable) {
        IPage<Team> queryPage = PageUtil.toMybatisPage(pageable);
        QueryWrapper<Team> predicate = QueryHelpMybatisPlus.getPredicate(query);
//        predicate.isNull("delete_id");
        predicate.orderByDesc("create_time");
        String managersName = query.getManagersName();
        if (managersName != null && !managersName.equals("")) {
            List<LoginUser> sysUserDtos = sysUserService.selectUserByNickName(managersName);
            predicate.and(wrap -> {
                for (LoginUser sysUserDto : sysUserDtos) {
                    wrap.eq("create_id", sysUserDto.getUserId()).or();
                }
            });
        }
        TableDataInfo<Team> build = TableDataInfo.build(queryPage);
        TableDataInfo<TeamDto> teamDtoTableDataInfo = MapstructUtils.convertTableDataInfo(build, TeamDto.class);

//        PageInfo<TeamDto> teamDtoPageInfo = ConvertUtil.convertPage(teamMapper.selectPage(queryPage, predicate), TeamDto.class);
        for (TeamDto teamDto : teamDtoTableDataInfo.getRows()) {
            teamDto.setOwnerName(teamDto.getOwner());
        }
//        teamDtoTableDataInfo.setPageSize(queryPage.getSize());
        return teamDtoTableDataInfo;
    }

    @Override
    public Team getById(Integer id) {
        return teamMapper.selectById(id);
    }

    @Override
    public TeamInformationVo getInformation(Integer id) {
        Team team = this.getById(id);
        LoginUser sysUser = sysUserService.getUserInfo(Long.valueOf(team.getOwner()));

        List<TeamMemberDto> memberByTeamId = teamMemberService.getMemberByTeamId(id);

        List<Object> objects = new ArrayList<>();
        TeamInformationVo teamInformationVo = new TeamInformationVo();
        teamInformationVo.setOwner(String.valueOf(sysUser.getUserId()));
        teamInformationVo.setOwnerName(sysUser.getNickname());
        teamInformationVo.setOwnerDept(sysDeptService.getById(sysUser.getDeptId()).getPath());
        teamInformationVo.setTeamName(team.getTeamName());
        teamInformationVo.setCreateTime(team.getCreateTime());
        teamInformationVo.setSpace(team.getSpace());
        teamInformationVo.setUsedSpace(team.getUsedSpace());
        teamInformationVo.setInstructions(team.getInstructions());
        teamInformationVo.setDefaultRole(team.getDefaultRole());
        for (TeamMemberDto teamMemberDto : memberByTeamId) {
            if (teamMemberDto.getObjectType().equals(PermTypeEnum.USER.getPermTypeCode())){
                objects.add(sysUserService.getUserInfo(teamMemberDto.getObjectId()));
            }
            if (teamMemberDto.getObjectType().equals(PermTypeEnum.DEPT.getPermTypeCode())){
                objects.add(sysDeptService.getById(teamMemberDto.getObjectId()));
            }
            if (teamMemberDto.getObjectType().equals(PermTypeEnum.ROLE.getPermTypeCode())){
                objects.add(sysRoleService.getById(teamMemberDto.getObjectId()));
            }
            if (teamMemberDto.getObjectType().equals(PermTypeEnum.JOB.getPermTypeCode())){
                objects.add(remotePostService.getById(teamMemberDto.getObjectId()));
            }

        }
        teamInformationVo.setTeamMember(objects);
        return teamInformationVo;
    }

    @Override
    // @Cacheable(key = "'id:' + #p0")
    public TeamDto findById(Integer id) {
        return MapstructUtils.convert(getById(id), TeamDto.class);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Team insert(TeamDto resources,boolean defaultRole) {
        resources.setUsedSpace(0L);
        LoginUser user = LoginHelper.getLoginUser();
        if (teamRename(resources.getTeamName(), user.getUserId())) {
            throw new RuntimeException("团队名称已存在");
        }
        Team entity = MapstructUtils.convert(resources, Team.class);
        String owner = resources.getOwner();

        if (owner == null || owner.equals("")) {
            entity.setOwner(String.valueOf(user.getUserId()));
        } else {
            entity.setOwner(owner);
        }

        CoreConfigDto teamMaxsize = coreConfigUtils.getByConfigCodeAfter("TEAM_MAXSIZE");
        String configValue = teamMaxsize.getConfigValue();
        Long maxSize = ByteUtil.gb2Byte(new BigDecimal(configValue));
        if (entity.getSpace() > maxSize) {
            throw new RuntimeException("超出设置最大空间大小");
        }
        entity.setCreateId(String.valueOf(user.getUserId()));
        entity.setCreateBy(user.getUsername());
        entity.setUpdateId(String.valueOf(user.getUserId()));
        entity.setUpdateBy(user.getUsername());
        teamMapper.insert(entity);
        entity.setMinioBucket("team-files-" + entity.getId());
        int insert = teamMapper.updateById(entity);
        TeamFilesTreeDto teamFilesTreeDto = new TeamFilesTreeDto();
        teamFilesTreeDto.setRealName(entity.getTeamName());
        teamFilesTreeDto.setTeamId(String.valueOf(entity.getId()));
        teamFilesTreeDto.setPath("/" + entity.getTeamName());
        teamFilesTreeDto.setType("head");
        TeamFilesTree teamFilesTree = createParentNode(teamFilesTreeDto);
        entity.setHeadNodeId(String.valueOf(teamFilesTree.getId()));

        Long ownerId = null;
        //创建默认角色和权限
        if (defaultRole){
            ownerId = teamRoleService.addDefaultRole(String.valueOf(entity.getId()));
        }else {
            ownerId = teamRoleService.addOwnerRole(String.valueOf(entity.getId())).getId();
        }

        TeamRelevanceRoleDto teamRelevanceRoleDto = new TeamRelevanceRoleDto();
        teamRelevanceRoleDto.setTeamId(String.valueOf(entity.getId()));
        teamRelevanceRoleDto.setObjectId(user.getUserId());
        teamRelevanceRoleDto.setObjectType(PermTypeEnum.USER.getPermTypeCode());
        teamRelevanceRoleDto.setRoleId(String.valueOf(ownerId));
        teamRelevanceRoleDto.setTreeNodeId(String.valueOf(teamFilesTree.getId()));
        teamRelevanceRoleService.insert(teamRelevanceRoleDto);

        //创建为成员
        TeamMemberDto teamMemberDto = new TeamMemberDto();
        teamMemberDto.setObjectId(user.getUserId());
        teamMemberDto.setObjectType(PermTypeEnum.USER.getPermTypeCode());
        teamMemberDto.setRoleId(String.valueOf(ownerId));
        teamMemberDto.setTeamId(entity.getId());
        teamMemberService.insert(teamMemberDto);

        //获取该团队的默认角色
        List<TeamRoleDto> role = teamRoleService.getRole(String.valueOf(entity.getId()));
        Long roleId = null;
        for (TeamRoleDto teamRoleDto : role) {
            if (teamRoleDto.getRank() == 3){
                roleId = teamRoleDto.getId();
                break;
            }
        }
        entity.setDefaultRole(String.valueOf(roleId));
        teamMapper.updateById(entity);
        return entity;
    }

    /**
     * 通过项目创建团队与创建模板文件
     *
     * @param resources 创建团队对象
     * @param members  成员集合
     * @param userInfoId 创建项目用户id
     * @return
     */
    @Override
    public TeamDto createTeamByProject(TeamDto resources, List<ProRoleToTeamRole> members, Long userInfoId) {
        LoginUser user = LoginHelper.getLoginUserByUserId(userInfoId);
        //创建团队
        resources.setType(TeamTypeEnum.PROJECT_TEAM.getNum());//设置项目团队
        Team insert = insert(resources,false);
        //获取该团队的默认角色
        List<TeamRoleDto> role = teamRoleService.getRole(String.valueOf(insert.getId()));
        TeamRoleDto ownerRole = null;
        for (TeamRoleDto teamRoleDto : role) {
            if (teamRoleDto.getRank() == 1){
                ownerRole = teamRoleDto;
            }
        }
        List<TeamMemberDto> teamRoleDtos = new ArrayList<>();

        //添加其他角色及团队成员
        for (ProRoleToTeamRole member : members) {
            //添加角色
            TeamRole teamRole = teamRoleService.addRole(member, String.valueOf(insert.getId()));
            Long teamRoleId = teamRole.getId();
            member.setTeamRoleId(teamRoleId);
            //添加成员
            MultiMap<Integer, Long> objects = member.getObjects();
            if (objects != null){
                for (Map.Entry<Integer, List<Long>> entry : objects.entrySet()) {
                    System.out.println("Key: " + entry.getKey() + ", Value: " + entry.getValue());
                    List<Long> value = entry.getValue();
                    for (Long s : value) {
                        TeamMemberDto teamMemberDto = new TeamMemberDto();
                        teamMemberDto.setTeamId(insert.getId());
                        teamMemberDto.setObjectType(entry.getKey());
                        teamMemberDto.setRoleId(String.valueOf(teamRoleId));
                        teamMemberDto.setObjectId(s);
                        teamRoleDtos.add(teamMemberDto);
                    }
                }
            }
        }
        if (!teamRoleDtos.isEmpty()){
            teamMemberService.addMembers(teamRoleDtos);
        }

        //添加团队成员
        if (resources.getTemplateId() != null && !StringUtils.isNullOrBlank(resources.getTemplateName()))
            //创建模板文件
            teamFilesTreeService.createTemplate(resources.getTemplateId(), Long.valueOf(insert.getHeadNodeId()), resources.getTemplateName(), user);
        TeamDto convert = MapstructUtils.convert(insert, TeamDto.class);
        convert.setRoleDtoList(role);
        ProRoleToTeamRole proRoleToTeamRole = MapstructUtils.convert(ownerRole, ProRoleToTeamRole.class);
        MultiMap<Integer,Long> objects = new MultiMap<>();
        List<Long> list = new ArrayList<>();
        list.add(userInfoId);
        objects.put(PermTypeEnum.USER.getPermTypeCode(),list);
        proRoleToTeamRole.setTeamRoleId(ownerRole.getId());
        proRoleToTeamRole.setObjects(objects);
        members.add(proRoleToTeamRole);
        convert.setMembers(members);
        return convert;
    }


    public TeamFilesTree createParentNode(TeamFilesTreeDto teamFilesTreeDto) {
        return teamFilesTreeService.insert(teamFilesTreeDto);
    }


    @Override
    public boolean teamRename(String name, Long userId) {
        QueryWrapper<Team> predicate = QueryHelpMybatisPlus.getPredicate(new TeamRoleQueryParam());
        predicate.eq("team_name", name);
        predicate.eq("owner", userId);
        predicate.isNull("delete_id");
        Integer integer = teamMapper.selectCount(predicate).intValue();
        return integer > 0;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public int updateById(TeamDto resources) {
        LoginUser loginUser = LoginHelper.getLoginUser();
        Team entity = MapstructUtils.convert(resources, Team.class);
        entity.setOwner(resources.getOwner());
        entity.setCreateId(String.valueOf(loginUser.getUserId()));
        entity.setCreateBy(loginUser.getNickname());
        entity.setUpdateId(String.valueOf(loginUser.getUserId()));
        entity.setUpdateBy(loginUser.getNickname());

        Team byId = getById(entity.getId());

//        //修改团队所有者时替换原有所有者的权限
//        if (entity.getOwner() != null) {
//            teamRelevanceRoleService.replaceOwner(byId.getOwner(), resources.getOwner(), entity.getId(),byId.getHeadNodeId());
//        }

        //修改空间不能大于已用空间
        if (entity.getSpace() != null) {
            if (entity.getSpace() < byId.getUsedSpace()) {
                throw new RuntimeException("超出已用空间大小");
            }
            CoreConfigDto teamMaxsize = coreConfigUtils.getByConfigCodeAfter("TEAM_MAXSIZE");
            String configValue = teamMaxsize.getConfigValue();
            Long maxSize = ByteUtil.gb2Byte(new BigDecimal(configValue));
            if (entity.getSpace() > maxSize) {
                throw new RuntimeException("超出设置最大空间大小");
            }
//            if (entity.getSpace() > fileStorageUtils.getMinioSpace().getAvailableSpaceCount()) {
//                throw new RuntimeException("超出剩余空间大小");
//            }
        }

        int ret = teamMapper.updateById(entity);
//        delCaches(resources.getId());
        return ret;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public int removeByIds(Set<Integer> ids) {
//        delCaches(ids);
        return teamMapper.deleteBatchIds(ids);
    }

    @Override
    public int ownerHandOver(TeamDto resources) {
        List<TeamRoleDto> role = teamRoleService.getRole(String.valueOf(resources.getId()));

        //修改团队成员
        List<TeamMemberDto> memberByTeamId = teamMemberService.getMemberByTeamId(resources.getId());
        Team team = teamMapper.selectById(resources.getId());
        //所有者角色id
        String ownerRoleId = null;
        for (TeamRoleDto teamRoleDto : role) {
            if (teamRoleDto.getRank() == 1){
                ownerRoleId = String.valueOf(teamRoleDto.getId());
            }
        }

        //老所有者
        String owner = team.getOwner();
        boolean flag = false;
        for (TeamMemberDto teamMemberDto : memberByTeamId) {
            if (teamMemberDto.getObjectId().toString().equals(owner) && Objects.equals(teamMemberDto.getObjectType(), PermTypeEnum.USER.getPermTypeCode())){
                //老所有者权限替换
                //优先设置团队的默认角色
                String defaultRole = team.getDefaultRole();
                if (defaultRole == null) {
                    for (TeamRoleDto teamRoleDto : role) {
                        if (teamRoleDto.getRank() == 2) {
                            teamMemberDto.setRoleId(String.valueOf(teamRoleDto.getId()));
                            break;
                        }
                    }
                }else {
                    teamMemberDto.setRoleId(defaultRole);
                }
                teamMemberService.updateById(teamMemberDto);
            }
            if (teamMemberDto.getObjectId().equals(Long.valueOf(resources.getOwner())) && teamMemberDto.getObjectType().equals(PermTypeEnum.USER.getPermTypeCode())){
                flag = true;
                //将新所有者原有的权限替换成所有者
                //将所有者改为该用户
                teamMemberDto.setRoleId(ownerRoleId);
                teamMemberService.updateById(teamMemberDto);
                teamRelevanceRoleService.updateRole(team.getHeadNodeId(),Long.valueOf(resources.getOwner()),PermTypeEnum.USER.getPermTypeCode(),ownerRoleId);
            }
        }
        if (!flag){
            //新所有者不是现有成员 添加为成员
            TeamMemberDto teamMemberDto = new TeamMemberDto();
            teamMemberDto.setTeamId(team.getId());
            teamMemberDto.setObjectId(Long.valueOf(resources.getOwner()));
            teamMemberDto.setObjectType(PermTypeEnum.USER.getPermTypeCode());
            teamMemberDto.setRoleId(ownerRoleId);
            teamMemberService.insert(teamMemberDto);
            TeamRelevanceRoleDto teamRelevanceRoleDto = new TeamRelevanceRoleDto();
            teamRelevanceRoleDto.setTeamId(String.valueOf(team.getId()));
            teamRelevanceRoleDto.setRoleId(teamMemberDto.getRoleId());
            teamRelevanceRoleDto.setTreeNodeId(team.getHeadNodeId());
            teamRelevanceRoleDto.setObjectId(teamMemberDto.getObjectId());
            teamRelevanceRoleDto.setObjectType(PermTypeEnum.USER.getPermTypeCode());
            teamRelevanceRoleService.insert(teamRelevanceRoleDto);
        }
        //替换原有团队所有者的团队文件权限（除文件所有者以外的文件）
        teamRelevanceRoleService.replaceOwnerOtherPerm(String.valueOf(team.getId()),owner,resources.getOwner());
        //修改团队
        return updateById(resources);
    }

    @Override
    public TableDataInfo<TeamDto> queryByDelete(TeamQueryParam query, Pageable pageable) {
        IPage<Team> queryPage = PageUtil.toMybatisPage(pageable);
        QueryWrapper<Team> predicate = QueryHelpMybatisPlus.getPredicate(query);
        predicate.isNotNull("delete_id");
        IPage<Team> page = teamMapper.selectPage(queryPage, predicate);
        TableDataInfo<Team> build = TableDataInfo.build(page);
        TableDataInfo<TeamDto> teamDtoTableDataInfo = MapstructUtils.convertTableDataInfo(build, TeamDto.class);

//        PageInfo<TeamDto> teamDtoPageInfo = ConvertUtil.convertPage(page, TeamDto.class);
        for (TeamDto teamDto : teamDtoTableDataInfo.getRows()) {
            teamDto.setCreateName(teamDto.getCreateId());
        }
        return teamDtoTableDataInfo;
    }

    @Override
    public int recoverTeam(Integer teamId) {
        return teamMapper.clearDeleteId(teamId);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public int removeById(Integer id) {
        Set<Integer> set = new HashSet<>(1);
        set.add(id);
        return this.removeByIds(set);
    }



//    @Cacheable(cacheNames = CacheKey.TREE_TEAM_NAME, key = "#teamId")
    @Override
    public String selectTeamNameById(String teamId) {
        Team team = teamMapper.selectOne(new LambdaQueryWrapper<Team>()
                .select(Team::getTeamName).eq(Team::getId, teamId));
        return ObjectUtil.isNull(team) ? null : team.getTeamName();
    }
//
//    private void delCaches(Integer id) {
//        redisUtils.del(CacheKey.TREE_TEAM_NAME + id);
//    }

//    private void delCaches(Set<Integer> ids) {
//        for (Integer id : ids) {
//            delCaches(id);
//        }
//    }



    /*
    @Override
    public void download(List<TeamDto> all, HttpServletResponse response) throws IOException {
      List<Map<String, Object>> list = new ArrayList<>();
      for (TeamDto team : all) {
        Map<String,Object> map = new LinkedHashMap<>();
              map.put("团队名称", team.getTeamName());
              map.put("说明", team.getExplain());
              map.put("头像", team.getPortrait());
              map.put("创建编号", team.getCreateId());
              map.put("创建者", team.getCreateBy());
              map.put("创建日期", team.getCreateTime());
              map.put("更新编号", team.getUpdateId());
              map.put("更新者", team.getUpdateBy());
              map.put("更新时间", team.getUpdateTime());
              map.put("删除编号", team.getDeleteId());
              map.put("删除者", team.getDeleteBy());
              map.put("删除时间", team.getDeleteTime());
        list.add(map);
      }
      FileUtil.downloadExcel(list, response);
    }*/
}
